package com.briup.jz.service.impl;

import com.briup.jz.bean.AccountSystemExample;
import com.briup.jz.bean.AccountSystem;
import com.briup.jz.bean.extend.AccountSystemExtend;
import com.briup.jz.dao.AccountSystemMapper;
import com.briup.jz.dao.extend.AccountSystemExtendMapper;
import com.briup.jz.service.IAccountSystemService;
import com.briup.jz.utils.CustomerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.List;

/**
 * @program: jz
 * @description: 用户系统业务实现类
 * @author: catmilko
 * @create: 2020/6/12 15:58
 **/
@Service
public class AccountSystemServiceImpl implements IAccountSystemService {
    @Resource
    private AccountSystemMapper accountSystemMapper;
    @Resource
    private AccountSystemExtendMapper accountSystemExtendMapper;

    @Override
    public List<AccountSystem> findAll() {
        return accountSystemMapper.selectByExample(new AccountSystemExample());
    }

    @Override
    public AccountSystem findById(long id) {
        return accountSystemMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(AccountSystem accountSystem) throws CustomerException {
        if (accountSystem.getId() == null) {
            accountSystemMapper.insert(accountSystem);
        } else {
            if (accountSystemMapper.selectByPrimaryKey(accountSystem.getId()) == null) {
                throw new CustomerException("修改失败，数据不存在");
            }
            accountSystemMapper.updateByPrimaryKey(accountSystem);
        }
    }

    @Override
    public void deleteById(long id) throws CustomerException {
        if (accountSystemMapper.selectByPrimaryKey(id) == null) {
            throw new CustomerException("删除失败，数据不存在");
        }
        accountSystemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<AccountSystemExtend> findAllWithOrderAndUser() {
        return accountSystemExtendMapper.selectAllWithOrderAndUser();
    }
}
